﻿/**********************************************************************
* @file   FITKAcousticsMaterialMgrAdaptor.h
* @brief  频谱数据读写适配器
* @author yangjing (1195810980@qq.com)
* @date   2025-02-25
*********************************************************************/
#ifndef _FITK_ACOUSTICS_SPECTRA_MGRADAPTOR_H__
#define _FITK_ACOUSTICS_SPECTRA_MGRADAPTOR_H__
#include "FITKAcousticsAbstractAdaptor.h"
#include "FITK_Kernel/FITKCore/FITKCoreMacros.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsSpectraManager.h"
#include "FITK_Kernel/FITKAdaptor/FITKIOAdaptorFactory.h"
#include <H5Cpp.h>
namespace IO {
    class FITKHDF5FileTool;
    class FITKAcousticsAbstractSpectra;
}
namespace IO {

    class FITKAcousticsSpectraMgrAdaptor : public FITKAcousticsAbsAdaptor
    {

    public:
        explicit FITKAcousticsSpectraMgrAdaptor() = default;
        virtual ~FITKAcousticsSpectraMgrAdaptor() = default;

        virtual bool adaptR() override;

        virtual bool adaptW() override;
    private:

        /**
        * @brief 读损耗因子谱hdf5到数据
        * @param @param[i]  SpectraGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readDamping(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);
        /**
        * @brief 写损耗因子谱数据到hdf5
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  Dampings    损耗因子谱数据
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writeDamping(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> Dampings);


        /**
        * @brief 写吸声系数谱数据到hdf5
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  AbsorptionCoefficients    吸声系数谱数据
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writeAbsorptionCoefficient(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> AbsorptionCoefficients);

        /**
        * @brief 读吸声系数据
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readAbsorptionCoefficient(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);


        /**
        * @brief 写模态密度
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  ModalDensitys    模态密度数据
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writeModalDensity(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> ModalDensitys);


        /**
        * @brief 读模态密度数据
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readModalDensity(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);

        /**
        * @brief 写波数谱数据
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  Wavenumberss    波数谱数据
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writeWavenumbers(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> Wavenumberss);


        /**
        * @brief 读波数谱数据
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readWavenumbers(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);

        /**
        * @brief 写耦合损耗因子谱数据
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  CouplingLossFactors    耦合损耗因子谱数据
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writeCouplingLossFactor(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> CouplingLossFactors);



        /**
        * @brief 读耦合损耗因子谱数据
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readCouplingLossFactor(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);


        /**
        * @brief 写传递损失数据
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  TransmissionLoss    传递损失
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writeTransmissionLoss(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> TransmissionLoss);

        /**
        * @brief 读传递损失数据
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readTransmissionLoss(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);


        /**
        * @brief 写插入损失数据
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  InsertionLoss    插入损失
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writeInsertionLoss(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> InsertionLoss);

        /**
        * @brief 读插入损失数据
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readInsertionLoss(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);



        /**
        * @brief 写剪切模量数据
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  ShearModulus    剪切模量
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writeShearModulus(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> ShearModulus);

        /**
        * @brief 读剪切模量数据
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readShearModulus(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);

        /**
        * @brief 写速度数据
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  Velocitys    剪切模量
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writeVelocitys(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> Velocitys);


        /**
        * @brief 读速度数据
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readVelocitys(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);



        /**
        * @brief 写角速度
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  AnlrVelocitys    角速度
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writeAnlrVelocitys(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> AnlrVelocitys);

        /**
        * @brief 读角速度
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readAnlrVelocitys(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);


        /**
        * @brief 写加速度
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  Accelerations  加速度
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writeAccelerations(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> Accelerations);

        /**
        * @brief 读加速度
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readAccelerations(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);

        /**
        * @brief 写力
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  Forces  力
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writeForces(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> Forces);


        /**
        * @brief 读力
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readForces(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);



        /**
        * @brief 写力矩
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  Moments  力矩
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writeMoments(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> Moments);


        /**
        * @brief 读力矩
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readMoments(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);

        /**
        * @brief 写声压
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  Pressures  声压
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writePressures(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> Pressures);


        /**
        * @brief 读声压
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readPressures(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);


        /**
        * @brief 写能量
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  Energys 能量
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writeEnergys(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> Energys);
        
        /**
        * @brief 读能量
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readEnergys(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);


        /**
        * @brief 写功率
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  Powers 功率
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool writePowers(H5::Group & SpectrGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> Powers);
        

        /**
        * @brief 读功率
        * @param @param[i]  SpectrGroup hdf5组别
        * @param @param[i]  mager    谱管理器
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        bool readPowers(H5::Group & SpectraGroup, Acoustics::FITKAcousticsSpectraManager * mager);
        

    private:

        /**
        * @brief 写公有数据，FITKAcousticsAbstractSpectra类的数据
        * @param @param[i]   SpectraGroup Goup组别
        * @param @param[i]   BaseData 数据
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-30
        */
        bool writeBaseData(H5::Group & SpectraGroup, QList<Acoustics::FITKAcousticsAbstractSpectra*> BaseData);


        /**
        * @brief 读取公有数据，FITKAcousticsAbstractSpectra类的数据
        * @param @param[i]   newObjData 要填写的类
        * @param @param[i]   thisGroup  读的那个组
        * @param @param[i]   i 索引
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-30
        */
        bool readBaseData(Acoustics::FITKAcousticsAbstractSpectra* newObjData, H5::Group thisGroup, int i);


        /**
         * @brief 判断是否全部为true
         * @param @param[i]  Data 数组
         * @author yangjing (1195810980@qq.com)
         * @date 2024-12-19
         */
        bool areAllTrue(const std::vector<bool>& Data);

        /**
        * @brief 拆分频率信息
        * @param @param[i]  SpectraValue 拆分的数据
        * @param @param[out]  hzv     拆分后的频率
        * @param @param[out]  realV   拆分后后实部
        * @param @param[out]  ImaginaryV     拆分后的虚部
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        void getSpectraValueData(QList<Acoustics::SpectraValue>&SpectraValue, std::vector<double>&hzv, std::vector<double>&realV, std::vector<double>&ImaginaryV);

        /**
        * @brief 合并频率信息
        * @param @param[i]  hzv     拆分后的频率
        * @param @param[i]  realV   拆分后后实部
        * @param @param[i]  ImaginaryV  拆分后的虚部
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        QList<Acoustics::SpectraValue>MergeSpectraValue(std::vector<double>&hzV, std::vector<double>&realV, std::vector<double>&ImaginaryV);


        /**
        * @brief 根据DomainType，获取字符串
        * @param @param[i]  Dtype 类型
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        std::string getDomainTypeString(Acoustics::FITKGlobalFrequencyDomain::DomainType Dtype);

        /**
        * @brief 根据字符串，获取Type
        * @param @param[i]  Str 类型
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-27
        */
        Acoustics::FITKGlobalFrequencyDomain::DomainType strFromType(std::string Str);

        /**
        * @brief检查是否含有特殊字符，没有则直接返回，有则转换
        * @param @param[i]  data 检查的字符串
        * @author yangjing (1195810980@qq.com)
        * @date 2024-12-19
        */
        QString RestoreStr(std::string data);
    private:
        IO::FITKHDF5FileTool*m_toolp{ nullptr };
    };
    Register2FITKIOAdaptorFactory(FITKAcousticsHDF5, Acoustics::FITKAcousticsSpectraManager, FITKAcousticsSpectraMgrAdaptor);
}

#endif